using System;
using System.Collections.Generic;
using System.Text;

namespace SSOConfigTool.Console
{
    /// <summary>
    /// Helper class for parsing console arguments
    /// </summary>
    public class ArgumentHelper
    {
        public static Dictionary<string, string> Arguments = new Dictionary<string, string>();

        /// <summary>
        /// Load the arguments passed to the command line
        /// </summary>
        /// <param name="args">Argument list</param>
        public static void LoadArguments(string[] args)
        {
            if (args.Length == 1 && args[0].IndexOf("?") > -1)
            {
                ShowUsage();
            }
            else
            {
                //set up arg dictionary:
                foreach (string arg in args)
                {
                    //special help.
                    if ((arg.StartsWith("-") || arg.StartsWith("/")) && !(arg.Equals("/?")))
                    {
                        string[] argParts = arg.Substring(1).Split('=');
                        if (argParts.Length == 2)
                        {
                            Arguments.Add(argParts[0], argParts[1]);
                        }
                        else
                        {
                            Arguments.Add(argParts[0], string.Empty);
                        }
                    }
                    else if (arg.Equals("/?"))
                    {
                        Arguments.Add("?", "?");
                    }
                }
            }
        }

        public static string GetArgument(string switchName)
        {
            return Arguments[switchName];
        }

        public static bool HasArgument(string switchName)
        {
            return Arguments.ContainsKey(switchName);
        }

        private static void ShowUsage()
        {
            //TODO
        }
    }
}
